[AJAX Numeric Updown Control] Microsoft JScript runtime error: The number of fractional digits is out of range

Posted by Jenson on Geeks with Blogs See other posts from Geeks with Blogs or by Jenson
Published on Wed, 22 Jun 2011 06:14:41 GMT Indexed on 2011/06/22 8:23 UTC
Read the original article Hit count: 205

Filed under:

If you have using Ajax control toolkits a lot (which I will skip the parts on where to download and how to configure it in Visual Studio 2010), you might have encountered some bugs or limitations of the controls, or rather, some weird behaviours. I would call them weird behaviours though.

Recently, I've been working on a Ajax numeric updown control, which i remember clearly it was working fine without problems. In fact, I use 2 numeric updown control this time.

So I went on to configure it to be as simple as possible and I will just use the default up and down buttons provided by it (so that I won't need to design my own). I have two textbox controls to display the value controlled by the updown control. One for month, and another for year.

<asp:TextBox ID="txtMonth" runat="server" CssClass="txtNumeric" ReadOnly="True" Width="150px" />

<asp:TextBox ID="txtYear" runat="server" CssClass="txtNumeric" ReadOnly="True" Width="150px" />

So I will now drop 1 numeric updown control for each of the textboxes.

<asp:NumericUpDownExtender ID="txtMonth_NumericUpDownExtender"
    runat="server" TargetControlID="txtMonth" Maximum="12" Minimum="1" Width="152">
</asp:NumericUpDownExtender>
                        
<asp:NumericUpDownExtender ID="txtYear_NumericUpDownExtender"
    runat="server" TargetControlID="txtYear" Width="152">
</asp:NumericUpDownExtender>                        
                        
You noticed that I configure the Maximum and Minimum value for the first numericupdown control, but I never did the same for the second one (for txtYear). That's because it won't work, well, at least for me.

So I remove the Minimum="2000" and Maximum="2099" from there. Then I would configure the initial value to the the current year, and let the year to flow up and down freely. If you want, you want write the codes to restrict it.

Here are the codes I used on PageLoad:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            If Trim(txtMonth.Text) = "" Then

                Me.txtMonth.Text = System.DateTime.Today.Month

            End If

            If Trim(txtYear.Text) = "" Then

                Me.txtYear.Text = System.DateTime.Today.Year

            End If

        End If

    End Sub
 


Enjoy!

© Geeks with Blogs or respective owner